package net.yc.imalachat.push.activities;



import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.ViewTarget;
import com.example.common.app.Activity;

import net.qiujuer.genius.ui.compat.UiCompat;
import net.yc.imalachat.push.R;
import net.yc.imalachat.push.frags.user.UpdateInfoFragment;

import butterknife.BindView;

/**
 * 用户信息界面
 * 可以提供用户信息修改
 */
public class UserActivity extends Activity {

    private static final String TAG = "UserActivity";

    private Fragment mCurrFragment;

    @BindView(R.id.im_bg)
    ImageView img;

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_user;
    }

    /**
     * Activity中收到的剪切图片成功的回调
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mCurrFragment.onActivityResult(requestCode, resultCode, data);
    }

    /**
     * 显示界面的入口方法
     */
    public static void show(Context mContext) {
        mContext.startActivity(new Intent(mContext, UserActivity.class));
    }

    @Override
    protected void initWidget() {
        super.initWidget();

        mCurrFragment = new UpdateInfoFragment();
        // 显示控件的方法
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.layout_container, mCurrFragment)
                .commit();

        // 背景初始化
        Glide.with(this)
                .load(R.drawable.bg_src_tianjin)
                .centerCrop()   // 居中剪切
                .into(new ViewTarget<ImageView, GlideDrawable>(img) {
                    @Override
                    public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                        // 拿到glide的Drawable
                        Drawable drawable = resource.getCurrent();
                        // 使用适配类进行包装
                        drawable = DrawableCompat.wrap(drawable);
                        drawable.setColorFilter(UiCompat.getColor(getResources(), R.color.colorAccent),
                                PorterDuff.Mode.SCREEN);    // 设置着色的效果和颜色，蒙版模式
                        // 设置给ImageView
                        this.view.setImageDrawable(drawable);
                    }
                });
    }
}